<?php

namespace Admin\Frontend\Controllers;

use Helpers\Main;
use Helpers\Tool;
use Helpers\Assets;
use Helpers\Template;
use Admin\Models\log\LoginLog;
use Admin\Models\server\BoxNet;
use Admin\Models\log\DeviceLoginLog;

class LogLoginController extends ControllerBase
{
    /**
     * [listAction description]
     * @return [html]     [login_log的页面]
     */
    public function indexAction()
    {
        $this->view->pick('log_login/index');
        Assets::easyUI('js/log_login/index.js');
        Main::showNavPosition();
    }

    /**
     * [searchAction description]
     * @return [json] [数据 源自 表 'login_log']
     */
    public function searchAction()
    {
        $requestData = $this->request->getPost();
        try {
            if ($this->request->isPost()) {
                $login_log = LoginLog::search($requestData);
                return $this->sendJsonResponse($login_log);
            } else {
                return $this->sendViewError('请求规则错误');
            }
        } catch (\Exception $e) {
            die($e->getMessage());
        }
    }

    /**
     * [dullIndexAction device_user_login_log 未登录操作折线图主页]
     * @method dullIndexAction
     * @return [page]          [折线图主页]
     */
    public function dullIndexAction()
    {
        Assets::xhChart();
        Assets::importMainCss('assets/simplify/simplify.css');
        Assets::importJs('js/log_login/dull_index.js');
        $dullModel = new DeviceLoginLog();
        $allCount  = $dullModel->getAllCount();
        foreach ($allCount as $key => $value) {
            $this->view->setVar($key, $value);
        }
        $today  = date('Y年m月d日', time());
        $before = date('Y-m-d', strtotime($params['curTime'] . '-7 day'));
        $this->view->setVar('title', $before . ' 至 ' . $today);
    }

    /**
     * [dullGetChartDataAction device_user_login_log 折线图获取数据]
     * @method dullGetChartDataAction
     * @return [string]                 [折线图获取数据]
     */
    public function dullGetChartDataAction()
    {
        $this->view->disable();
        if ($this->request->isPost()) {
            $dullModel = new DeviceLoginLog();
            $params    = array();
            $data      = $dullModel->getDataForDays($params);
            return $this->sendJsonResponse($data);
        } else {
            return $this->sendViewError('请求规则错误');
        }
    }

    /**
     * [dullDetailAction device_user_login_log 未登录操作详情页]
     * @method dullDetailAction
     * @return [page]           [未登录操作详情页]
     */
    public function dullDetailAction()
    {
        Assets::easyUI();
        Assets::importJs('js/log_login/dull_detail.js');
        Main::showNavPosition();
    }


    /**
     * [dullGetAllClassAction device_user_login_log 所有班级人员/未操作人员]
     * @method dullGetAllClassAction
     * @return [string]                [所有班级人员/未操作人员]
     */
    public function dullGetAllClassAction()
    {
        $this->view->disable();
        $requestData = $this->request->getPost();
        if ($this->request->isPost()) {
            $dullModel = new DeviceLoginLog();
            $data      = $dullModel->getByAllClass($requestData);
            return $this->sendJsonResponse($data);
        } else {
            return $this->sendViewError('请求规则错误');
        }
    }

    /**
     * [dullGetNameListAction device_user_login_log 获取未操作人详细名单]
     * @method dullGetNameListAction
     * @return [string]                [获取未操作人详细名单]
     */
    public function dullGetNameListAction()
    {
        $this->view->disable();
        $requestData = $this->request->getPost();
        $dullModel   = new DeviceLoginLog();
        $data        = $dullModel->getByGrades($requestData);
        return $this->sendJsonResponse($data);
    }


}
